/**
 * 
 */
package data;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import domain.Article;
import domain.Supplier;

/**
 * @author grupo22
 *
 */
public class JDBCSupplierDAO implements ISupplierDAO {

	/* (non-Javadoc)
	 * @see data.ISupplierDAO#select(java.sql.Connection, java.lang.String)
	 */
	@Override
	public Supplier select(Connection con, String oid) {
		String sql = "SELECT * FROM Supplier WHERE (OIDSupplier = ? )";
        PreparedStatement stmt = null;
        ResultSet rs = null;
        Supplier sup = null;

        try {
            stmt = con.prepareStatement(sql);
            stmt.setString(1, oid);

            rs = stmt.executeQuery();

            rs.next();
            int bidderCode = new Integer(rs.getString("bidderCode")).intValue();
            String address = rs.getString("address");
            String name = rs.getString("name");
            String email = rs.getString("email");
            double reputation = new Double(rs.getDouble("reputation")).intValue();
            sup = new Supplier(bidderCode, address, name, email, reputation);
            
        } catch (SQLException e) {
            System.out.println("Message: " + e.getMessage());
            System.out.println("SQLState: " + e.getSQLState());
            System.out.println("ErrorCode: " + e.getErrorCode());
        } finally {
            try {
                if (rs != null) {
                    rs.close();
                }
                if (stmt != null) {
                    stmt.close();
                }
            } catch (SQLException e) { }
        }
        return sup;
	}

}
